home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / alib / csup / math_support / ascint.asm < prev    next >
Assembly Source File  |  1994-02-14  |  8KB  |  269 lines

  1.  
  2.  
  3. *       ************************************************
  4. *       ** Math Lib C Interface - ASCII Conversion     **
  5. *       **                         **
  6. *       ************************************************
  7.  
  8.  
  9. ***********************************************************************
  10. **                                      *
  11. **   Copyright 1984, Amiga Computer Inc.   All rights reserved.       *
  12. **   No part of this program may be reproduced, transmitted,          *
  13. **   transcribed, stored in retrieval system, or translated into      *
  14. **   any language or computer language, in any form or by any          *
  15. **   means, electronic, mechanical, magnetic, optical, chemical,      *
  16. **   manual or otherwise, without the prior written permission of     *
  17. **   Amiga Computer Incorporated, 3350 Scott Blvd, Bld #7,          *
  18. **   Santa Clara, CA 95051                          *
  19. **                                      *
  20. ***********************************************************************
  21.  
  22.     xdef    _afp,_fpa,_dbf,_arnd        * C entries for conversion math functions
  23.  
  24.     xref    FFPAFP,FFPFPA,FFPDBF,FFPARND
  25.  
  26.  
  27.  
  28. ******* amiga.lib/afp **************************************************
  29. *
  30. *   NAME
  31. *    afp - Convert ASCII string variable into fast floating point
  32. *
  33. *   SYNOPSIS
  34. *    ffp_value = afp(string);
  35. *
  36. *    FUNCTION
  37. *    Accepts the address of the ASCII string in C format that is
  38. *    converted into an FFP floating point number.
  39. *
  40. *    The string is expected in this Format:
  41. *    {S}{digits}{'.'}{digits}{'E'}{S}{digits}
  42. *    <*******MANTISSA*******><***EXPONENT***>
  43. *
  44. *
  45. *    Syntax rules:
  46. *    Both signs are optional and are '+' or '-'. The mantissa must be
  47. *    present. The exponent need not be present. The mantissa may lead
  48. *    with a decimal point. The mantissa need not have a decimal point.
  49. *    Examples: All of these values represent the number fourty-two.
  50. *             42        .042e3
  51. *             42.      +.042e+03
  52. *            +42.      0.000042e6
  53. *        0000042.00     420000e-4
  54. *                 420000.00e-0004
  55. *
  56. *    Floating point range:
  57. *    Fast floating point supports the value zero and non-zero values
  58. *    within the following bounds -
  59. *            18                   20
  60. *     9.22337177 x 10   > +number >    5.42101070 x 10
  61. *            18                   -20
  62. *    -9.22337177 x 10   > -number > -2.71050535 x 10
  63. *
  64. *    Precision:
  65. *    This conversion results in a 24 bit precision with guaranteed
  66. *    error less than or equal to one-half least significant bit.
  67. *
  68. *    INPUTS
  69. *    string - Pointer to the ASCII string to be converted.
  70. *
  71. *
  72. *    OUTPUTS
  73. *    string - points to the character which terminated the scan
  74. *    equ - fast floating point equivalent
  75. *****************************************************************************
  76.  
  77. _afp:
  78.     movem.l d3-d7,-(sp)         * Save registers used
  79.     move.l    24(sp),a0           * Put ASCII string address in A0
  80.     jsr    FFPAFP            * Execute Motorola function
  81.     bra.s    fpal3            * Set up functional result and exit
  82.  
  83.  
  84. ******* amiga.lib/fpa **************************************************
  85. *
  86. *   NAME
  87. *    fpa - convert fast floating point into ASCII string equivalent
  88. *
  89. *   SYNOPSIS
  90. *    exp = fpa(fnum, &string[0]);
  91. *
  92. *   FUNCTION
  93. *    Accepts an FFP number and the address of the ASCII string where it's
  94. *    converted output is to be stored.  The number is converted to a NULL
  95. *    terminated ASCII string in and stored at the address provided.
  96. *    Additionally, the base ten (10) exponent in binary form is returned.
  97. *
  98. *   INPUTS
  99. *    fnum       - Motorola Fast Floating Point number
  100. *    &string[0] - address for output of converted ASCII character string
  101. *             (16 bytes)
  102. *
  103. *   RESULT
  104. *    &string[0] - converted ASCII character string
  105. *    exp       - integer exponent value in binary form
  106. *
  107. *   BUGS
  108. *    None
  109. *****************************************************************************
  110. * Docs recovered 9/1/88 from Rob Peck's sun - Bryce
  111.  
  112.  
  113. _fpa:
  114.     movem.l d3-d7,-(sp)         * Save registers used
  115.     move.l    24(sp),d7           * Put FFP number to convert in D7
  116.     jsr    FFPFPA            * Execute Motorola function
  117.  
  118.     move.l    42(sp),a0           * Put ASCII string address in A0
  119. fpal1:
  120.     moveq    #6,d1            * Set up for 14 byte data transfer
  121. fpal2:
  122.     move    (sp)+,(a0)+         * Move one (1) word at a time
  123.     dbf    d1,fpal2        * Loop until all 14 bytes moved
  124. fpal3:
  125.     move.l    d7,d0            * Get exponent as functional value
  126.     movem.l (sp)+,d3-d7         * Restore registers used
  127.     rts
  128.  
  129.  
  130. ******* amiga.lib/dbf **************************************************
  131. *
  132. *   NAME
  133. *    dbf - convert FFP dual-binary number to FFP format
  134. *
  135. *   SYNOPSIS
  136. *    fnum = dbf(exp, mant);
  137. *
  138. *   FUNCTION
  139. *    Accepts a dual-binary format (described below) floating point
  140. *    number and converts it to an FFP format floating point number.
  141. *    The dual-binary format is defined as:
  142. *
  143. *        exp bit  16    = sign (0=>positive, 1=>negative)
  144. *        exp bits 15-0    = binary integer representing the base
  145. *                      ten (10) exponent
  146. *        man        = binary integer mantissa
  147. *
  148. *   INPUTS
  149. *    exp - binary integer representing sign and exponent
  150. *    mant - binary integer representing the mantissa
  151. *
  152. *   RESULT
  153. *    fnum - converted FFP floating point format number
  154. *
  155. *   BUGS
  156. *    None
  157. *****************************************************************************
  158.  
  159.  
  160.  
  161. _dbf:
  162.     movem.l d3-d7,-(sp)         * Save registers used
  163.     moveq    #0,d6            * Insure D6 is cleared
  164.     move.l    28(sp),d7           * D7 = mantissa
  165.     tst.l    d7
  166.     bpl    dbfl1
  167.     bset    #16,d6            * Set negative mantissa indicator
  168.     neg.l    d7            * Convert to positive mantissa value
  169. dbfl1:
  170.     move    26(sp),d6           * Set up actual exponent value
  171.     jsr    FFPDBF            * Execute Motorola function
  172.     bra.s    fpal3            * Set up functional result and exit
  173.  
  174.  
  175.  
  176. ******* amiga.lib/arnd *************************************************
  177. *
  178. *  NAME
  179. *    arnd - ASCII round of the provided floating point string
  180. *
  181. *   SYNOPSIS
  182. *    arnd(place, exp, &string[0]);
  183. *
  184. *   FUNCTION
  185. *    Accepts an ASCII string representing an FFP floating point
  186. *    number, the binary representation of the exponent of said
  187. *    floating point number and the number of places to round to.
  188. *    A rounding process is initiated, either to the left or right
  189. *    of the decimal place and the result placed back at the
  190. *    input address defined by &string[0].
  191. *
  192. *   INPUTS
  193. *    place - integer representing number of decimal places to round to
  194. *    exp - integer representing exponent value of the ASCII string
  195. *    &string[0] - address where rounded ASCII string is to be placed
  196. *             (16 bytes)
  197. *
  198. *   RESULT
  199. *    &string[0] - rounded ASCII string
  200. *
  201. *   BUGS
  202. *    None
  203. *****************************************************************************
  204.  
  205.  
  206. _arnd:
  207.     movem.l d3-d7,-(sp)         * Save registers used
  208.  
  209.     movem.l 24(sp),d6-d7        * Set up rounding magnitude and exponent
  210.     move.l    32(sp),a0           * Get address of ASCII string
  211.  
  212.     lea    -14(sp),a1          * Point A1 to stack area
  213.     move.l    a1,sp            * Point SP there too
  214.     moveq    #6,d1            * Set up for 7 word mem-mem move
  215. arndl1:
  216.     move    (a0)+,(a1)+         * Move one (1) word at a time
  217.     dbf    d1,arndl1        * Loop until all 7 words moved
  218.  
  219.     jsr    FFPARND         * Execute Motorola function
  220.  
  221.     move.l    46(sp),a0           * Get string address for result
  222.     bra.s    fpal1            * Move the string and get out
  223.  
  224.  
  225.  
  226. ****i** amiga.lib/fpbcd ************************************************
  227. *
  228. *   NAME
  229. *    fpbcd - convert FFP floating point number to BCD format
  230. *
  231. *   SYNOPSIS
  232. *    fpbcd(fnum, &string[0]);
  233. *
  234. *   FUNCTION
  235. *    Accepts a floating point number and the address where the
  236. *    converted BCD data is to be stored.  The FFP number is
  237. *    converted and stored at the specified address in an ASCII
  238. *    form in accordance with the following format:
  239. *
  240. *        MMMM S E S B
  241. *
  242. *    Where:    M = Four bytes of BCD, each with two (2) digits of
  243. *            the mantissa (8 digits)
  244. *        S = Sign of mantissa (0x00 = positive, 0xFF = negative)
  245. *        E = BCD byte for two (2) digit exponent
  246. *        S = Sign of exponent (0x00 = positive, 0xFF = negative)
  247. *        B = One (1) byte binary two's compliment representation
  248. *            of the exponent
  249. *
  250. *   INPUTS
  251. *    fnum - floating point number
  252. *    &string[0] - address where converted BCD data is to be placed
  253. *
  254. *   RESULT
  255. *    &string[0] - converted BCD data
  256. *****************************************************************************
  257.  
  258.  
  259. ;_fpbcd:
  260. ;    movem.l d3-d7,-(sp)         * Save registers used
  261. ;    move.l    24(sp),d7           * Put FFP value in D7
  262. ;    jsr    FFPFPBCD        * Execute Motorola function
  263. ;    move.l    40(sp),a0           * Put ASCII string address in A0
  264. ;    moveq    #3,d1            * Set up for 8 byte data transfer
  265. ;    bra.s    fpal2            * Move the string and get out
  266.  
  267.  
  268.     end
  269.